package com.ftx.controller.test.future;

import javax.inject.Inject;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * Created by fengtingxin on 2021/2/18 9:43 下午
 */
public class Client {


    private static final int from_Acount = 1001;

    private static final int to_Acount = 1002;

    public static void test1(){
        System.out.println("just is test  threadName is : " + Thread.currentThread().getName());
    }


    ////无返回值
    public static void runAsync() throws Exception{

        Client temp = new Client();
        CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {
            test1();
        });
        completableFuture.get();
    }


    ////有返回值
    public static void supplyAsync() throws Exception{

        Client temp = new Client();
        CompletableFuture<Long> completableFuture = CompletableFuture.supplyAsync(() -> {
            long start = System.currentTimeMillis();
            test1();
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
            }
            return System.currentTimeMillis() - start;
        });
        completableFuture.get();

    }
}
